package com.dense.kuiniu.bookborrow.business.adapter;

import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.dense.kuiniu.bookborrow.R;
import com.dense.kuiniu.bookborrow.business.entity.Book;
import com.dense.kuiniu.bookborrow.utils.RandomCoverUtils;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * @author Administrator
 * @date 2020/8/7
 */
public class BookSearchAdapter extends BaseQuickAdapter<Book, BaseViewHolder> implements LoadMoreModule {
    public BookSearchAdapter(int layoutResId, @Nullable List<Book> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, Book bookBean) {
        ImageView cover = baseViewHolder.getView(R.id.iv_cover);
        Glide.with(getContext())
                .load(bookBean.getCoverPhotoUrl())
                .centerCrop()
                .error(RandomCoverUtils.getRandomCover())
                .placeholder(RandomCoverUtils.getRandomCover())
                .into(cover);
        baseViewHolder.setText(R.id.tv_name, String.format("《%s》", bookBean.getBookName()));
        baseViewHolder.setText(R.id.tv_author, bookBean.getAuthor());
        baseViewHolder.setText(R.id.tv_count, String.valueOf(bookBean.getCount()));
        baseViewHolder.setText(R.id.tv_location, bookBean.getLocation());
        baseViewHolder.setText(R.id.tv_state, bookBean.getState());
        baseViewHolder.setTextColor(R.id.tv_state, "1".equals(bookBean.getStateCode()) ? Color.parseColor("#00C96D") :
                Color.parseColor("#FF451A"));
        ImageView tag = baseViewHolder.getView(R.id.iv_tag_periodical);
        if ("0".equals(bookBean.getBop())) {
            //图书
            tag.setVisibility(View.INVISIBLE);
        } else {
            tag.setVisibility(View.VISIBLE);
        }
    }
}